package org.ontobrowser.ontoextract;

import java.net.URI;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.w3c.dom.Element;
import org.w3c.dom.NodeList;

public class Class {

	Element classNode;

	List<Property> properties;
	HashMap<URI, Property> hierachicalProperties;

	public Class(Element element) {
		classNode = element;
	}

	public void setProperties(List<Property> properties) {
		this.properties = properties;
	}
	
	public List<Property> getProperties() {
		return this.properties;
	}
	
	public String getLabel()
	{
		String value = RDFDomUtil.getElementAttributeValue(classNode, RDFDomUtil.RDFSCHEMA_NS, "label"); // in the case that the label is an attribute
		
		return value;
	}
	
	public String getComment()
	{
		String value = RDFDomUtil.getElementAttributeValue(classNode, RDFDomUtil.RDFSCHEMA_NS, "comment"); // in the case that the label is an attribute
		
		return value;
	}
	
	public String getType()
	{		
		Element typeNode = RDFDomUtil.getChildNode(classNode, RDFDomUtil.RDF_NS, "type");
		if(typeNode!=null)			
			return RDFDomUtil.getElementAttributeValue(typeNode, RDFDomUtil.RDF_NS, "resource");
		
		return null;
	}
	
	public String getDefinedBy()
	{	
		Element definedNode = RDFDomUtil.getChildNode(classNode, RDFDomUtil.RDFSCHEMA_NS, "isDefinedBy");
		if(definedNode!= null)
		{
			return RDFDomUtil.getElementAttributeValue(definedNode, RDFDomUtil.RDF_NS, "resource");
		}
		
		return null;
	}
	
	public List<String> getSubClasses()
	{
		List<String> subclasses = new ArrayList<String>();
		
		NodeList subClassList = classNode.getElementsByTagNameNS(RDFDomUtil.RDFSCHEMA_NS, "subClassOf");
		if(subClassList!= null)
		{		
			for(int i=0; i<subClassList.getLength(); i++) {
		    	Element subClassElement = (Element) subClassList.item(i);
		    	String subclass = RDFDomUtil.getElementAttributeValue(subClassElement, RDFDomUtil.RDF_NS, "resource");
		    		
	    		subclasses.add(subclass);	    		
		    }
		}
		
		return subclasses;
	}

	public void print() {
		
		String value = RDFDomUtil.getElementAttributeValue(classNode, RDFDomUtil.RDFSCHEMA_NS, "label"); // in the case that the label is an attribute

		System.out.println(" Class   -  " + value);
		
		if(properties != null)
		{
			for(Property property : properties)
			{
				property.print();
			}
		}
		
		System.out.println();
		System.out.println();
		
	}

	public String getAbout() {
		return RDFDomUtil.getElementAttributeValue(classNode, RDFDomUtil.RDF_NS, "about");
	}

	
}
